//
//  YuViewController.m
//  盘盈贷
//
//  Created by iOS on 15/3/24.
//  Copyright (c) 2015年 Yunpeng Technologies. All rights reserved.
//

#import "YuViewController.h"
#import "AFHTTPRequestOperationManager.h"
#import "yue.h"
#import "yueTableViewCell.h"
@interface YuViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableArray *Array;
@end

@implementation YuViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        self.title = @"可用余额";
       
        self.Array = [NSMutableArray array];
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    NSLog(@"yue:%@", self.yue);
    UIView *top = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 3)];
    //top.backgroundColor = [UIColor redColor];
    [self.view addSubview:top];
    [top release];
    UILabel *yuan = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 120, 20)];
    yuan.text = @"账户余额 (元)";
    yuan.textColor = [UIColor redColor];
    [top addSubview:yuan];
    [yuan release];
    
    
    UILabel *toplabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 45, self.view.frame.size.width, 60)];
    toplabel.backgroundColor = [UIColor whiteColor];
    toplabel.text = self.yue;
    toplabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:40];
    toplabel.textColor = [UIColor redColor];
    toplabel.textAlignment = NSTextAlignmentCenter;
    [top addSubview:toplabel];
    [toplabel release];
    
    UIButton *chongzhi = [UIButton buttonWithType:UIButtonTypeSystem];
    chongzhi.frame = CGRectMake(60, 150, 100, 30);
    chongzhi.center = CGPointMake(80, 150);
    [chongzhi setTitle:@"充值" forState:UIControlStateNormal];
    chongzhi.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
    chongzhi.backgroundColor = [UIColor redColor];
    [chongzhi setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [chongzhi addTarget:self action:@selector(chongzhi:) forControlEvents:UIControlEventTouchUpInside];
    [top addSubview:chongzhi];
    
    UIButton *tixian = [UIButton buttonWithType:UIButtonTypeSystem];
    tixian.frame = CGRectMake(240, 150, 100, 30);
    tixian.center = CGPointMake(240, 150);
    [tixian setTitle:@"提现" forState:UIControlStateNormal];
    tixian.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
    tixian.backgroundColor = [UIColor redColor];
    [tixian setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [tixian addTarget:self action:@selector(tixian:) forControlEvents:UIControlEventTouchUpInside];
    [top addSubview:tixian];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = YES;
     self.tableView.tableHeaderView = top;
    [self.view addSubview:self.tableView];
    [self.tableView release];
    
//    NSString *str = @"http://www.cloudpeng.com:8102/account/GetRecharge?strusername=chenying";
    NSString *str = [NSString stringWithFormat:@"http://www.cloudpeng.com:8102/account/GetRecharge?strusername=%@", self.strusername];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        for (NSDictionary *dic in responseObject) {
            yue *model = [[yue alloc] initWithDictionary:dic];
            
            // self.userID = model.userid;
            
            [self.Array addObject:model];
            
        }
        [self.tableView reloadData];
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"~~~~~~~%@",error);
    }];
}
//设置tableview 每个分区(section)显示多少行(row)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return [self.Array count];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
        
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
   yueTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"3"];
        if (cell == nil) {
            cell = [[yueTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"3"];
        }
    NSString *time = [[self.Array objectAtIndex:indexPath.row] CreateTime];
    NSArray *timearray = [time componentsSeparatedByString:@"T"]; //从字符A中分隔成2个元素的数组
    cell.riqi.text =[NSString stringWithFormat:@"%@", [timearray objectAtIndex:0]];
    NSString *q = [NSString stringWithFormat:@"%@", [timearray objectAtIndex:1]];
    cell.riqi1.text = [q substringToIndex:8];
    
    if ([[[self.Array objectAtIndex:indexPath.row] Amount] intValue] > 1000) {
       
    NSMutableString *t3 = [NSMutableString stringWithFormat:@"%@.00元", [[self.Array objectAtIndex:indexPath.row] Amount]];
    
    [t3 insertString:@"," atIndex:1];
    cell.jine.text = t3;
    } else {
        cell.jine.text = [NSString stringWithFormat:@"%@.00元", [[self.Array objectAtIndex:indexPath.row] Amount]];
    }
//    if ([[[self.Array objectAtIndex:indexPath.row] PayStatus] isEqual:@"1"]) {
//        cell.leixing.text = @"所有";
//    }
    cell.leixing.text = @"所有";
    cell.name.text = @"0.00元";
        return cell;
    
}
- (void)viewDidAppear:(BOOL)animated
{
    NSLog(@"@@@@@@@%@", _yue);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
